package com.curry.livehelper.entity.domain;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class MenuTree {


    public static Map<String, Object> mapArray = new LinkedHashMap<String, Object>();
    public List<TMenuInfo> menuCommon;
    public List<Object> list = new ArrayList<Object>();

    public List<Object> menuList(List<TMenuInfo> menu) {
        this.menuCommon = menu;
        for (TMenuInfo x : menu) {
            Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
            if ("0".equals(x.getParentId())) {
                mapArr.put("id", x.getId());
                mapArr.put("name", x.getMenuName());
                mapArr.put("level", x.getLevel());
                mapArr.put("pid", x.getParentId());
                mapArr.put("url", x.getUrl());
                mapArr.put("sort", x.getSort());
                mapArr.put("icon", x.getIcon());
                mapArr.put("child", menuChild(x.getId()));
                list.add(mapArr);
            }
        }
        return list;
    }


    public List<?> menuChild(int id) {
        List<Object> lists = new ArrayList<Object>();
        for (TMenuInfo a : menuCommon) {
            Map<String, Object> childArrays = new LinkedHashMap<String, Object>();
            if (a.getParentId().equals(String.valueOf(id))) {
                childArrays.put("id", a.getId());
                childArrays.put("name", a.getMenuName());
                childArrays.put("level", a.getLevel());
                childArrays.put("pid", a.getParentId());
                childArrays.put("url", a.getUrl());
                childArrays.put("sort", a.getSort());
                childArrays.put("icon", a.getIcon());
                childArrays.put("child", menuChild(a.getId()));
                lists.add(childArrays);
            }
        }
        return lists;

    }
}  
